﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TCHSHue.BLL;
using System.IO;

namespace TCHSHue.Modules.IndexControl.TinTuc
{
    public partial class ctrTinTucIndex : System.Web.UI.UserControl
    {

        int pSize = 5;
        int pCurrent = 1;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                
                NapDanhSachTinTuc();
                NapDanhSachThongBao();
            }
        }
        void NapDanhSachTinTuc()
        {
            //var idNoiBat = TheLoaiBLL.getIdBaiVietNoiBat(HangTheLoai.TINTUC);
            var ls = BaiVietBLL.getListTheoTrang(Hang.TINTUC, pSize, pCurrent, (int)TinhTrangBaiViet.DaDuyet);
            if (ls.Count == 0)
            {
                tintuc_sukien.Visible = false;
                return;
            }

            #region Bài viết nổi bật
            //if (idNoiBat != null)
            //{
            //    var bv = BaiVietBLL.getBaiViet(idNoiBat);
            //    if (bv != null)
            //    {
            //        tieuDeNoiBat.Text = Server.HtmlDecode(bv.chuDe);
            //        tieuDeNoiBat.NavigateUrl = "~/Modules/Index.aspx?mode=chitiettintuc&id=" + bv.maBaiViet + "&idTL=" + bv.maTheLoai;
            //        lbNoiDungNoiBat.Text = Server.HtmlDecode(bv.noiDungTomTat);
            //        if (!string.IsNullOrEmpty(bv.anhDaiDienUrl))
            //            imgNoiBat.ImageUrl = "~/Upload/ImageArticle/" + bv.anhDaiDienUrl;

            //        if (ls != null && ls.Count >= 1)
            //        {
            //            var item = ls.Where(t => t.MaBaiViet == new Guid(idNoiBat)).SingleOrDefault();
            //            if (item != null)
            //                ls.Remove(item);
            //        }
            //    }
            //    else
            //    {
            //        if (ls != null && ls.Count >= 1)
            //        {
            //            tieuDeNoiBat.Text = Server.HtmlDecode(ls[0].ChuDe);
            //            tieuDeNoiBat.NavigateUrl = "~/Modules/Index.aspx?mode=chitiettintuc" + ls[0].MaBaiViet + "&idTL=" + ls[0].MaTheLoai;
            //            lbNoiDungNoiBat.Text = Server.HtmlDecode(ls[0].NoiDungTomTat);
            //            if (!string.IsNullOrEmpty(ls[0].AnhDaiDienURL))
            //                imgNoiBat.ImageUrl = "~/Upload/ImageArticle/" + ls[0].AnhDaiDienURL;
            //            ls.RemoveAt(0);
            //        }
            //    }
            //}
            //else
            //{
            //    if (ls != null && ls.Count >= 1)
            //    {
            //        tieuDeNoiBat.Text = Server.HtmlDecode(ls[0].ChuDe);
            //        tieuDeNoiBat.NavigateUrl = "~/Modules/Index.aspx?mode=chitietbaiviet" + ls[0].MaBaiViet + "&idTL=" + ls[0].MaTheLoai;
            //        lbNoiDungNoiBat.Text = Server.HtmlDecode(ls[0].NoiDungTomTat);
            //        if (!string.IsNullOrEmpty(ls[0].AnhDaiDienURL))
            //            imgNoiBat.ImageUrl = "~/Upload/ImageArticle/" + ls[0].AnhDaiDienURL;
            //        ls.RemoveAt(0);
            //    }
            //} 
            #endregion

            ddlDSBaiViet.DataSource = ls;
            ddlDSBaiViet.DataBind();

        }
        void NapDanhSachThongBao()
        {
            var ls = BaiVietBLL.getListTheoTrang(Hang.THONGBAO, pSize, pCurrent, (int)TinhTrangBaiViet.DaDuyet);
            if (ls.Count == 0)
            {
                thongbao.Visible = false;
                return;
            }
            ddlThongBao.DataSource = ls;
            ddlThongBao.DataBind();
        }
        
    }
}